﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@using OBUCare.Web.Models;
@using OBUCare.Core.Common;
@{
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();


    var operatorInfo = UIUtility.GetCurrentUser();


    //var menuNames = ViewData["menuName"];


    string agentNO = operatorInfo.AgentNo; //UIUtility.getAgentByModule(operatorInfo, menuNames.ToString());
}
@using (Html.BeginForm("PartsStockInSearch", "PartsReport", FormMethod.Post, new { @id = "searchForm" }))
{

    <table style="width: 100%">
        <tr style="height: 40px;">
            <td align="right" width="20%">
                入库日期：
            </td>
            <td align="left" width="30%">
                @Html.Telerik().DatePicker().Name("FromCreatedDate").OpenOnFocus(true).HtmlAttributes(new { style = "width: 170px" }).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
            <td align="right" width="20%">
                至：
            </td>
            <td align="left" width="30%">
                @Html.Telerik().DatePicker().Name("ToCreatedDate").OpenOnFocus(true).HtmlAttributes(new { style = "width: 170px" }).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
        </tr>
        <tr style="height: 40px;">
            <td align="right">
                厂商：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("Supplier").BindTo(ddlHelper.GetSuppliers(UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).ClientEvents(e => e.OnChange("changeSpecs"))
            </td>
            <td align="right">
                型号：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("SpecName").BindTo(ddlHelper.GetPartsSpecs(null, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
        </tr>
        <tr>
            <td align="right">
                元器件：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("PartType").BindTo(ddlHelper.GetPartTypes(UIConstants.AllItems, true, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
            <td align="right">
                入库类别：
            </td>
            <td align="left">
                @Html.Telerik().DropDownList().Name("StockType").BindTo(ViewBag.ListData)
                @*(ddlHelper.GetInStockBy(ViewBag.StockType, true, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).Enable((ViewBag.Enable).Equals(UIConstants.AllItems))*@
            </td>
            <td colspan="2" align="center">
                <input type="button" value="查询" id="btnSearch" />
                @Html.Hidden("searchSql", "", new { @id = "searchSql" })
                @Html.Hidden("agentNO", agentNO, new { @id = "agentNO" })
                @* @Html.Hidden("menuNames", menuNames, new { @id = "menuNames" })*@
            </td>
        </tr>
    </table>
    
    
}
<script type="text/javascript">

    $().ready(function () {

        $('#btnSearch').click(function () {
            search();
        });

        @*if ("@agentNO".length != 0) {
            var agentType = $('#AgentType').data('tDropDownList');
            var transferBillStatus = $('#TransferBillStatus').data('tDropDownList');
            agentType.select(1); agentType.disable();
        }*@
    });


    function search() {
        var form = $("#searchForm");
        dataString = form.serialize();
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: dataString,
            cache: false,
            dataType: "json",
            success: function (data) {

                if (data.Success) {
                    //alert('成功');
                    //debugger;
                    var grid = $('#Grid').data('tGrid')
                    $('#searchSql').val(data.Sql)
                    grid.rebind();
                }
                else {
                    alert('失败：' + data.ErrorMsg)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                alert(err);
            }
        });
    }

    function changeSpecs(e)
    {
       var SpecName = $('#SpecName').data('tDropDownList');
        var value = e.currentTarget.value;
        $.post("/PartsReport/getSpecs", { "supplierID": value}, function (data) {
            SpecName.dataBind(data);
            if (SpecName != null) {
                SpecName.select(0);
            }
        });
    }

</script>
@{
    ddlHelper.Dispose();    
}
